// Copyright 2023 Srhino Co., Ltd. All rights reserved.

package utils

import (
	"os"
	"path/filepath"

	"go.uber.org/zap"

	"git.ouryun.cn/base/go-kit/pkg/log"
)

var Logger *zap.SugaredLogger

func init() {
	log.SetDefaultWrappedLogger(log.NewWrappedLogger(setLoggerOptionInternal()...))
	Logger = log.GetSugaredLogger()
}

func setLoggerOptionInternal() []log.LoggerOption {
	var opts []log.LoggerOption

	if execPath, err := os.Executable(); err == nil {
		opts = append(opts, log.WithFilename(filepath.Join(filepath.Dir(execPath), "logs", "info.log")))
	}
	opts = append(opts, log.WithStdOut(true))
	return opts
}
